jQuery(function(){
	jQuery('.addBtn').on('click',function(){
		window.location = window.rootPath+"/ui/aftersaleexperience/add";
	})

	//获取显示页面数据 服务器分页
	var serverData = {};
	var serverTable;


	serverTable = jQuery('#accessTable').DataTable({
		"serverSide": true,
		"ordering": false,
		"ajax": {
			"dataType": "json",
			"type": "get",
			"cache": false,
			"url":window.rootPath+ '/ui/aftersaleexperience/getpage',
			"data": function (d) {
				return $.extend({}, d, serverData);
			}
		},
		columns: [
			{
				data: null,
				defaultContent: ""//排序
			},
			{
				data: null,
				defaultContent: "",
				render: function (data, type, full, meta) {

					var id=data.id
					var operate ='<input type="checkbox" class="checkchild">';
					return operate;

				}
			},
			{
				data: 'customer',
                render:function(data,type,full,meta){
                	if(data == null || data == undefined || data == ""){
						return data;
					}else{
						return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
					}
				}

			},
			{
				data: 'deviceType',
                render:function(data,type,full,meta){
                	if(data == null || data == undefined || data == ""){
						return data;
					}else{
						return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
					}
				}
			},
			{
				data: 'recordDate',
				render : function(data,
								  type, full,
								  meta) {
					if (data) {
						return moment(data).format("YYYY-MM-DD");
					}
				}
			},
			{
				data: 'memo',
                render:function(data,type,full,meta){
                	if(data == null || data == undefined || data == ""){
						return data;
					}else{
						return (data.length > 18) ? '<font title="'+data+'">'+data.substring(0,18)+'...'+'</font>' : data;
					}
				}
			},
			{
				data:'attachCount',
				 render: function (data, type, full, meta) {
                 	var dOut;
                 	if(data==null){
                 		dOut='<td class="center" ><span class="badge label-pill label-primary">'+0+'</span></td>'
                 	}else{
                 		dOut='<td class="center" ><span class="badge label-pill label-primary">'+data+'</span></td>'
                 	}
                 	return dOut;
                 }
			}

		],
		"drawCallback": function (oSettings) {
			var k = 0;
			var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

			for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
				$('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
				k++;
			}

		}
	});
//列表全选
	 $("#checkAll").click(function(){
		 	var check = $(this).prop("checked");
		     $(".checkchild").prop("checked", check);
			});

	////编辑
	jQuery('.editBtn').on('click', function () {
		var selects=getSelect("#accessTable",1);
		if(selects.length>1){
			$.springLemonDialog({
				content: '只能编辑一条记录',// 确认文本
				clickButton: function (sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			});
		}
		else if(selects.length==0){
			$.springLemonDialog({
				content: '请选择要编辑的记录',// 确认文本
				clickButton: function (sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			});
		}else if(selects.length==1){
			var id=selects[0].id;
			window.location = window.rootPath+"/ui/aftersaleexperience/edit"+"?id="+id;
		}
	});
	/////删除客户/////
	jQuery('.delBtn').on('click', function () {
		var selects=getSelect("#accessTable",1);
		var url=window.rootPath+"/ui/aftersaleexperience/del";
		delSelect(selects,url,serverTable)
	});
	//客户查询
	jQuery('.searchBtn').on('click', function() {
		serverData.key = jQuery('#keyword').val();
		serverTable.draw();
	})
	// 撤销客户查询
	jQuery('.cancelBtn').on("click", function() {
		jQuery('#keyword').val('');
		serverData.key = '';
		serverTable.draw();
	});

});
